#!/bin/bash

# 检查参数
if [ "$#" -ne 2 ]; then
    echo "Usage: $0 source_file target_directory"
    exit 1
fi

SOURCE_FILE=$1
TARGET_DIR=$2

# 检查源文件是否存在
if [ ! -f "$SOURCE_FILE" ]; then
    echo "Source file does not exist."
    exit 1
fi

# 检查目标目录是否存在，不存在则创建
if [ ! -d "$TARGET_DIR" ]; then
    mkdir -p "$TARGET_DIR"
fi

# 备份文件
cp "$SOURCE_FILE" "$TARGET_DIR"
echo "File $SOURCE_FILE backed up to $TARGET_DIR"

